home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / w_util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  5.6 KB  |  210 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "figx.h"
  15. #include "resources.h"
  16. #include "w_drawprim.h"
  17. #include "w_util.h"
  18. #include "w_setup.h"
  19.  
  20. /*
  21.  * The next routine is easy to implement, but I haven't missed it yet.
  22.  * Generally it is a bad idea to warp the mouse without the users consent.
  23.  */
  24.  
  25. win_setmouseposition(w, x, y)
  26.     Window        w;
  27.     int            x, y;
  28. {
  29. }
  30.  
  31. /* manually flush out X events */
  32.  
  33. app_flush()
  34. {
  35.     while (XtAppPending(tool_app)) {
  36.     XEvent        event;
  37.  
  38.     /* pass events to ensure we are completely initialised */
  39.     XtAppNextEvent(tool_app, &event);
  40.     XtDispatchEvent(&event);
  41.     }
  42. }
  43.  
  44. /* popup a confirmation window */
  45.  
  46. static        query_result, query_done;
  47. static String   query_translations =
  48.         "<Message>WM_PROTOCOLS: DismissQuery()\n";
  49. static void     accept_cancel();
  50. static XtActionsRec     query_actions[] =
  51. {
  52.     {"DismissQuery", (XtActionProc) accept_cancel},
  53. };
  54.  
  55.  
  56. static void
  57. accept_yes()
  58. {
  59.     query_done = 1;
  60.     query_result = RESULT_YES;
  61. }
  62.  
  63. static void
  64. accept_no()
  65. {
  66.     query_done = 1;
  67.     query_result = RESULT_NO;
  68. }
  69.  
  70. static void
  71. accept_cancel()
  72. {
  73.     query_done = 1;
  74.     query_result = RESULT_CANCEL;
  75. }
  76.  
  77. int
  78. popup_query(query_type, message)
  79.     int            query_type;
  80.     char       *message;
  81. {
  82.     TOOL        query_popup, query_form, query_message;
  83.     TOOL        query_yes, query_no, query_cancel;
  84.     int            xposn, yposn;
  85.     Window        win;
  86.     XEvent        event;
  87.     static int      actions_added=0;
  88.     extern Atom        wm_delete_window;
  89.  
  90.     DeclareArgs(7);
  91.  
  92.     XTranslateCoordinates(tool_d, canvas_win, XDefaultRootWindow(tool_d),
  93.               150, 200, &xposn, &yposn, &win);
  94.     FirstArg(XtNallowShellResize, True);
  95.     NextArg(XtNx, xposn);
  96.     NextArg(XtNy, yposn);
  97.     NextArg(XtNborderWidth, POPUP_BW);
  98.     NextArg(XtNtitle, "Xfig: Query");
  99.     query_popup = XtCreatePopupShell("query_popup", transientShellWidgetClass,
  100.                      tool, Args, ArgCount);
  101.     XtOverrideTranslations(query_popup,
  102.                        XtParseTranslationTable(query_translations));
  103.     if (!actions_added) {
  104.         XtAppAddActions(tool_app, query_actions, XtNumber(query_actions));
  105.     actions_added = 1;
  106.     }
  107.  
  108.     FirstArg(XtNdefaultDistance, 10);
  109.     query_form = XtCreateManagedWidget("query_form", formWidgetClass,
  110.                        query_popup, Args, ArgCount);
  111.  
  112.     FirstArg(XtNfont, bold_font);
  113.     NextArg(XtNborderWidth, 0);
  114.     NextArg(XtNlabel, message);
  115.     query_message = XtCreateManagedWidget("message", labelWidgetClass,
  116.                       query_form, Args, ArgCount);
  117.  
  118.     FirstArg(XtNheight, 25);
  119.     NextArg(XtNvertDistance, 15);
  120.     NextArg(XtNfromVert, query_message);
  121.     NextArg(XtNborderWidth, INTERNAL_BW);
  122.     NextArg(XtNlabel, " Yes  ");
  123.     NextArg(XtNhorizDistance, 55);
  124.     query_yes = XtCreateManagedWidget("yes", commandWidgetClass,
  125.                       query_form, Args, ArgCount);
  126.     XtAddEventHandler(query_yes, ButtonReleaseMask, (Boolean) 0,
  127.               (XtEventHandler)accept_yes, (XtPointer) NULL);
  128.  
  129.     if (query_type == QUERY_YESNO) {
  130.     ArgCount = 4;
  131.     NextArg(XtNhorizDistance, 25);
  132.     NextArg(XtNlabel, "  No  ");
  133.     NextArg(XtNfromHoriz, query_yes);
  134.     query_no = XtCreateManagedWidget("no", commandWidgetClass,
  135.                      query_form, Args, ArgCount);
  136.     XtAddEventHandler(query_no, ButtonReleaseMask, (Boolean) 0,
  137.               (XtEventHandler)accept_no, (XtPointer) NULL);
  138.  
  139.     ArgCount = 5;
  140.     NextArg(XtNfromHoriz, query_no);
  141.     } else {
  142.     ArgCount = 4;
  143.     NextArg(XtNhorizDistance, 25);
  144.     NextArg(XtNfromHoriz, query_yes);
  145.     }
  146.  
  147.     NextArg(XtNlabel, "Cancel");
  148.     query_cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  149.                      query_form, Args, ArgCount);
  150.     XtAddEventHandler(query_cancel, ButtonReleaseMask, (Boolean) 0,
  151.               (XtEventHandler)accept_cancel, (XtPointer) NULL);
  152.  
  153.     XtPopup(query_popup, XtGrabExclusive);
  154.     (void) XSetWMProtocols(XtDisplay(query_popup), XtWindow(query_popup),
  155.                            &wm_delete_window, 1);
  156.     XDefineCursor(tool_d, XtWindow(query_popup), arrow_cursor);
  157.  
  158.     query_done = 0;
  159.     while (!query_done) {
  160.     /* pass events */
  161.     XNextEvent(tool_d, &event);
  162.     XtDispatchEvent(&event);
  163.     }
  164.  
  165.     XtPopdown(query_popup);
  166.     XtDestroyWidget(query_popup);
  167.  
  168.     return (query_result);
  169. }
  170.  
  171. static void
  172. CvtStringToFloat(args, num_args, fromVal, toVal)
  173.     XrmValuePtr        args;
  174.     Cardinal       *num_args;
  175.     XrmValuePtr        fromVal;
  176.     XrmValuePtr        toVal;
  177. {
  178.     static float    f;
  179.  
  180.     if (*num_args != 0)
  181.     XtWarning("String to Float conversion needs no extra arguments");
  182.     if (sscanf((char *) fromVal->addr, "%f", &f) == 1) {
  183.     (*toVal).size = sizeof(float);
  184.     (*toVal).addr = (caddr_t) & f;
  185.     } else
  186.     XtStringConversionWarning((char *) fromVal->addr, "Float");
  187. }
  188.  
  189. static void
  190. CvtIntToFloat(args, num_args, fromVal, toVal)
  191.     XrmValuePtr        args;
  192.     Cardinal       *num_args;
  193.     XrmValuePtr        fromVal;
  194.     XrmValuePtr        toVal;
  195. {
  196.     static float    f;
  197.  
  198.     if (*num_args != 0)
  199.     XtWarning("Int to Float conversion needs no extra arguments");
  200.     f = *(int *) fromVal->addr;
  201.     (*toVal).size = sizeof(float);
  202.     (*toVal).addr = (caddr_t) & f;
  203. }
  204.  
  205. fix_converters()
  206. {
  207.     XtAppAddConverter(tool_app, "String", "Float", CvtStringToFloat, NULL, 0);
  208.     XtAppAddConverter(tool_app, "Int", "Float", CvtIntToFloat, NULL, 0);
  209. }
  210.